package com.ruoyi.auth.exception;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class UserDetailsExceptionInterceptor {

    @AfterThrowing(throwing = "ex", pointcut = "execution(* org.springframework.security.core.userdetails.UserDetailsService.*(..))")
    public void handle(Exception ex) {
        /*if (ex instanceof RpcException) {
            log.error("RpcException:{}", ex.getMessage(), ex);
            RpcException exception = (RpcException) ex;
            if (exception.getCode() == RpcException.UNKNOWN_EXCEPTION) {
                throw new CommonException(CommonException.UNKNOWN_EXCEPTION);
            } else if (exception.getCode() == RpcException.NETWORK_EXCEPTION) {
                throw new CommonException(CommonException.NETWORK_EXCEPTION);
            } else if (exception.getCode() == RpcException.TIMEOUT_EXCEPTION) {
                throw new CommonException(CommonException.TIMEOUT_EXCEPTION);
            } else if (exception.getCode() == RpcException.FORBIDDEN_EXCEPTION
                    || exception.getCode() == RpcException.NO_INVOKER_AVAILABLE_AFTER_FILTER) {
                throw new CommonException(CommonException.SERVICE_EXCEPTION);
            } else {
                throw (RpcException) ex;
            }

        }*/
    }

/*    @Before("execution(* com.ruoyi.common.security.service.*(..))")
    public void beforHandle(){
//        com.ruoyi.system.api.service.IDeptApiService;
        log.error("Intercept dubbo beforHandle:");

    }*/

}
